package com.masterclient.app.modules.shop.widget;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.R;
import com.masterclient.app.modules.shop.adapter.StockExplainAdapter;
import com.masterclient.app.modules.shop.beans.StockExplainBean;

public class StockExplainDialog extends Dialog {

    private final Activity mContext;
    StockExplainBean stockExplainBean;
    private final int pageType;

    public StockExplainDialog(@NonNull Activity context, StockExplainBean stockExplainBean, int pageType) {
        super(context, R.style.MyDialog);
        this.stockExplainBean = stockExplainBean;
        this.pageType = pageType;
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_stock_explain);
        setCanceledOnTouchOutside(true);

        TextView tvTitle = findViewById(R.id.tv_title);
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        StockExplainAdapter stockExplainAdapter = new StockExplainAdapter(mContext);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(stockExplainAdapter);

        if (pageType == 1) {
            tvTitle.setText(stockExplainBean.homeExplain.title);
            stockExplainAdapter.setNewData(stockExplainBean.homeExplain.paragraphList);
        } else {
            tvTitle.setText(stockExplainBean.storeExplain.title);
            stockExplainAdapter.setNewData(stockExplainBean.storeExplain.paragraphList);
        }
        findViewById(R.id.tv_confirm).setOnClickListener(v -> dismiss());
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        windowParams.width = ScreenUtils.getScreenWidth();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowParams);
    }
}
